package cn.itcast.bos.service.base.impl;

import cn.itcast.bos.Dao.base.PromotionRepositroy;


import cn.itcast.bos.domain.take_delivey.PageBean;
import cn.itcast.bos.domain.take_delivey.Promotion;
import cn.itcast.bos.service.base.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {
    @Autowired
    private PromotionRepositroy promotionRepositroy;
    @Override
    public void save(Promotion model) {
        promotionRepositroy.save(model);
    }

    @Override
    public Page<Promotion> findPageData(PageRequest pageRequest) {
        return promotionRepositroy.findAll(pageRequest);
    }

    @Override
    public PageBean findPageData(int page, int rows) {

        System.out.println(page+"    "+rows);
        PageRequest pageable = new PageRequest(page - 1, rows);
        Page<Promotion> pageData = promotionRepositroy.findAll(pageable);
        //System.out.println(pageData);
        PageBean pageBean = new PageBean();
        pageBean.setTotalCount(pageData.getTotalElements());
        pageBean.setPageData(pageData.getContent());
        return pageBean;
    }


}
